package com.example.dell.newstart.my;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.newstart.R;
import com.example.dell.newstart.base.ActivityCollector;
import com.example.dell.newstart.base.BaseActivity;
import com.example.dell.newstart.bean.MyApp;
import com.example.dell.newstart.bean.User;
import com.example.dell.newstart.login.Login;
import com.example.dell.newstart.utils.SharedPreferenceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MySetUpActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.my_setup_username)
    TextView etSetupUsername;
    @BindView(R.id.my_setup_zhanghao)
    TextView etSetupZhanghao;
    private Button loginout;
    private ImageView mReturnView;
    private ImageView turnInfor;
    @Override
    public int initLayout() {
        return R.layout.activity_mysetup;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);//注册butterknife（起作用）
        mReturnView=findViewById(R.id.my_set_return);
        mReturnView.setOnClickListener(this);
        turnInfor=findViewById(R.id.turn_infor);
        turnInfor.setOnClickListener(this);
        loginout = findViewById(R.id.loginout_btn);
        loginout.setOnClickListener(this);
    }

    @Override
    public void initData() {
        if (MyApp.getCurrentUser()!=null) {
            etSetupUsername.setText(MyApp.getCurrentUser().getUsername());
            etSetupZhanghao.setText((MyApp.getCurrentUser().getId()).toString());
            //toastShort("点击了512");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.my_set_return:
                finish();
                break;
            case R.id.turn_infor:
                User user = MyApp.getCurrentUser();
                if (user == null) {
                    toastShort("未登录");
                    goNextActivity(Login.class);
                    return;
                }
                else
                goNextActivity(MyInformationActivity.class);
                break;
            case R.id.loginout_btn:
                MyApp app2 = (MyApp) getApplication();
                app2.setCurrentUser(null);
                // TODO: 2018/12/21 调用后台接口，执行相关逻辑。
                SharedPreferenceUtil.put(getContext(),"autoLogin",false);
                goNextActivity(Login.class);
                ActivityCollector.finishAll();
                break;
        }
    }
}
